We’re using two new packages:
plotly is the R interface to the Plotly graphing libraryreticulate allows us to run Python code from within R.library(tidyverse)
library(ggplot2)
library(plotly)
library(reticulate)
# This is needed to avoid a crash on the RStudio server
# https://github.com/rstudio/reticulate/issues/849
py_run_string("import matplotlib.pyplot as plt; plt.switch_backend('agg')")
This chunk is just a quick demo of running Python code and showing the result.
# https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula
import math
sum(16 ** -k * (4/(8*k+1) - 2/(8*k+4) - 1/(8*k+5) - 1/(8*k+6)) for k in range(100)) - math.pi
## 0.0
Import the Python packages that we’ll need:
import matplotlib.pyplot as plt
import seaborn as sns
daily_rides <- read_csv("data/day.csv")
First, using ggplotly:
p <- ggplot(daily_rides, aes(x = date, y = total)) +
geom_line()
ggplotly(p)
Then, using plot_ly:
daily_rides %>%
plot_ly(x = ~date, y = ~total) %>%
add_lines() %>%
layout(title = "YOUR TITLE HERE")
## Warning: `arrange_()` is deprecated as of dplyr 0.7.0.
## Please use `arrange()` instead.
## See vignette('programming') for more help
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
Finally, using Seaborn.
rides = r.daily_rides
sns.relplot(x = "date", y = "total", kind = "line", data = rides);
plt.xlabel("Date")
plt.ylabel("Total number of rides")
plt.show()